package com.xxxx.seckill.test.rabbitMq.listen;

import com.xxxx.seckill.test.rabbitMq.method.SendMethod;
import io.lettuce.core.dynamic.annotation.Key;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;

import static com.xxxx.seckill.test.rabbitMq.conf.MqNames.*;

@Slf4j
@Component
public class NormalListener {


    @RabbitListener(queues = WORK_QUEUE)
    public void listen01(Object obj) throws InterruptedException {
        log.info(" LISTEN1 : NORMAL QUEUE :{} 。。。", obj);
        Thread.sleep(20);
    }

    @RabbitListener(queues = WORK_QUEUE)
    public void listen02(Object obj) throws InterruptedException {
        log.info(" LISTEN2 : NORMAL QUEUE :{} 。。。", obj);
        Thread.sleep(200);
    }


    // fanout
    @RabbitListener(bindings = @QueueBinding(
            value = @Queue(name = FANOUT_QUEUE01),
            exchange = @Exchange(name = EXCHANGE_FANOUT, type = "fanout")
    ))
    public void listen03(String s) throws InterruptedException {
        log.info(" LISTEN1 : NORMAL QUEUE :{} 。。。", s);
    }


    @RabbitListener(bindings = @QueueBinding(
            value = @Queue(name = FANOUT_QUEUE02),
            exchange = @Exchange(name = EXCHANGE_FANOUT, type = "fanout")
    ))
    public void listen04(String s) throws InterruptedException {
        log.info(" LISTEN2 : NORMAL QUEUE :{} 。。。", s);
    }

    //Direct
    @RabbitListener(bindings = @QueueBinding(
            value = @Queue(name = DIRECT_QUEUE01),
            exchange = @Exchange(name = EXCHANGE_DIRECT, type = "direct"),
            key = "red"
    ))
    public void listen05(String s) {
        log.info(" LISTEN1(red) : Direct QUEUE :{} 。。。", s);
    }


    @RabbitListener(bindings = @QueueBinding(
            value = @Queue(name = DIRECT_QUEUE02),
            exchange = @Exchange(name = EXCHANGE_DIRECT, type = "direct"),
            key = "green"
    ))
    public void listen06(String s) {
        log.info(" LISTEN2(green) : Direct QUEUE :{} 。。。", s);
    }

    @RabbitListener(bindings = @QueueBinding(
            value = @Queue(name = TOPIC_QUEUE01),
            exchange = @Exchange(name = EXCHANGE_TOPIC,type = "topic"),
            key = "china.*"
    ))
    public void listen07(String s){
        log.info(" LISTEN2(china.*) : Topic QUEUE :{} 。。。", s);
    }

    @RabbitListener(bindings = @QueueBinding(
            value = @Queue(name = TOPIC_QUEUE01),
            exchange = @Exchange(name = EXCHANGE_TOPIC,type = "topic"),
            key = "#.news"
    ))
    public void listen08(String s){
        log.info(" LISTEN2(#.news) : Topic QUEUE :{} 。。。", s);
    }
}
